package com.lyf.scm.admin.api.controller;

import com.github.pagehelper.PageInfo;
import com.lyf.scm.admin.api.dto.DateLabelDTO;
import com.lyf.scm.admin.domain.remote.basedata.dto.AreaDTO;
import com.lyf.scm.admin.domain.remote.basedata.dto.SearchStoreParamDTO;
import com.lyf.scm.admin.domain.remote.basedata.dto.StoreDTO;
import com.lyf.scm.admin.domain.remote.basedata.facade.BaseDataFacade;
import com.lyf.scm.admin.domain.remote.item.dto.CategoryBaseInfoDTO;
import com.lyf.scm.admin.domain.remote.item.dto.UnitTypeDTO;
import com.lyf.scm.admin.domain.service.OutService;
import com.lyf.scm.common.model.SalesPlanSelectDTO;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.util.controller.RomeController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author 李兵兵
 * @date 2020/08/12
 */
@Api(tags = "外围服务数据中心")
@RequestMapping("/api/v1/outService")
@RomeController
public class OutServiceController {
    @Resource
    private OutService outService;
    @Resource
    private BaseDataFacade baseDataFacade;

    @ApiOperation("查询品类的层级接口")
    @PostMapping("/getCategoryListByLevel")
    public Response<List<CategoryBaseInfoDTO>> getCategoryListByLevel(Integer level) {
        return Response.builderSuccess(outService.getCategoryListByLevel(level));
    }

    @ApiOperation("根据品类的code查询后台类目信息")
    @PostMapping("/categoryListByCategoryCodes")
    public Response<List<CategoryBaseInfoDTO>> categoryListByCategoryCodes(@RequestBody List<String> stringList) {
        return Response.builderSuccess(outService.categoryListByCategoryCodes(stringList));
    }

    @ApiOperation("单个根据类目ID查询SKU数据")
    @GetMapping("/skuListByCategoryId/{categoryId}/{pageNum}/{pageSize}")
    public Response<List<SalesPlanSelectDTO>> skuListByCategoryId(@PathVariable Long categoryId, @PathVariable Integer pageNum,
                                                           @PathVariable Integer pageSize) {
        return Response.builderSuccess(outService.skuListByCategoryId(categoryId, pageNum, pageSize));
    }

    @ApiOperation(value = "根据Level等级获取区域信息")
    @PostMapping("/searchAreaByLevels")
    public Response<PageInfo<AreaDTO>> searchAreaByLevels(@RequestBody List<Integer> level){
        return Response.builderSuccess(outService.searchAreaByLevels(level));
    }
    @ApiOperation(value = "根据角色获取最高级区域信息")
    @GetMapping("/searchAreaByRole")
    public Response<List<AreaDTO>> searchAreaByRole(){
        return Response.builderSuccess(outService.searchAreaByRole());
    }

    @ApiOperation(value = "根据parentCode获取所有下级地址根")
    @GetMapping("/searchByParentCode")
    public Response<List<SalesPlanSelectDTO>> searchByParentCode(@RequestParam("parentCode") String parentCode){
        return Response.builderSuccess(outService.searchByParentCode(parentCode));
    }

    @GetMapping("/dateLabels")
    @ApiOperation(value = "根据当前日期获取前三周后十四周公立节假日（对计划接口）")
    public Response<List<DateLabelDTO>> getDateLabels(@RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate) {
        return Response.builderSuccess(outService.getDateLabels(startDate));
    }

    @GetMapping("/listUnitType")
    @ApiOperation("查询采购单位接口")
    public Response<List<UnitTypeDTO>> listUnitType(){
        return Response.builderSuccess(outService.listUnitType());
    }

    @GetMapping("/listSaleOrg")
    @ApiOperation("查询所有公司的接口")
    public Response<List<SalesPlanSelectDTO>> listSaleOrg(){
        return Response.builderSuccess(outService.listSaleOrg());
    }

    @GetMapping("/parentChannel")
    @ApiOperation("根据父渠道查询子渠道")
    public Response<List<SalesPlanSelectDTO>> parentChannel(@RequestParam String parentChannel){
        return Response.builderSuccess(outService.parentChannel(parentChannel));
    }

    @GetMapping("/queryByLevel")
    @ApiOperation("根据渠道等级查询渠道信息")
    public Response<List<SalesPlanSelectDTO>> queryByLevel(@RequestParam Integer level){
        return Response.builderSuccess(outService.queryByLevel(level));
    }

    @PostMapping("/listStore")
    @ApiOperation("筛选出对应区域的门店")
    public Response<List<SalesPlanSelectDTO>> listStore(@RequestBody SearchStoreParamDTO storeParamDTO,
                                              @RequestParam Integer pageNum,
                                              @RequestParam Integer pageSize){
        return Response.builderSuccess(outService.listStore(storeParamDTO,pageNum,pageSize));
    }
    @GetMapping("/stock/factory/type")
    @ApiOperation("通过类型查询仓库")
    public Response<List<StoreDTO>> queryFactoryByRwType(@RequestParam("realWarehouseType") Integer realWarehouseType){
        return Response.builderSuccess(outService.queryFactoryByRwType(realWarehouseType));
    }

    @ApiOperation(value = "查询所有区域列表")
    @GetMapping("/searchAllAreaList")
    public Response<List<AreaDTO>> searchAllAreaList(){
        return Response.builderSuccess(outService.searchAllAreaList());
    }

    @ApiOperation(value = "分页查询省市区")
    @GetMapping("/searchAreaPage")
    public Response<PageInfo<AreaDTO>> searchAreaPage(Integer pageNum, Integer pageSize){
        //TODO
        PageInfo<AreaDTO> pageInfo = baseDataFacade.getAreaByLevels(Arrays.asList(0, 1, 2, 3), pageNum, pageSize);
        return Response.builderSuccess(pageInfo);
    }

    @ApiOperation(value = "分页查询门店")
    @GetMapping("/searchStorePage")
    public Response<PageInfo<AreaDTO>> searchStorePage(String codeOrName, Integer pageNum, Integer pageSize){
        StoreDTO storeDTO = new StoreDTO();
        storeDTO.setCodeOrName(codeOrName);
        PageInfo<StoreDTO> pageInfo = baseDataFacade.listStore(storeDTO, pageNum, pageSize);
        return Response.builderSuccess(pageInfo);
    }
}
